package plantable;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

public class TableRenderer extends DefaultTableCellRenderer {

	public TableRenderer() {
		setHorizontalAlignment(JLabel.RIGHT);
		setHorizontalTextPosition(SwingConstants.RIGHT);
	}

	public final Component getTableCellRendererComponent(JTable table,
			Object value, boolean isSelected, boolean hasFocus, int row, int col) {

		if (value instanceof String) {
			if (((String) value).startsWith("p")) {
				setBackground(Color.RED);
			} else {
				setBackground(null);
			}
		}

		return super.getTableCellRendererComponent(table, value, isSelected,
				hasFocus, row, col);
	}
}
